package com.example.spring.iocbug;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author houyangfan
 * @version 1.0
 * @date 2022/8/3 10:09
 */
@RestController
@Slf4j
@RequestMapping("/ioc")
public class IocBugTest {

    @Autowired
    private List<SayService> sayServiceList;

    @Autowired
    private ApplicationContext applicationContext;
    @GetMapping("test")
    public void test() {

        log.info("====================");
        sayServiceList.forEach(SayService::say);
    }

    @GetMapping("test2")
    public void test2() {

        log.info("====================");
        // sayServiceList.forEach(SayService::say);
        applicationContext.getBeansOfType(SayService.class).values().forEach(SayService::say);
    }

}
